import siyuan from "siyuan";
import siyuanConnect from "../../../widgets/common/SiyuanConnect"
export default class SiyuanSamplePlugin extends Plugin {
  constructor() {
    super();
  }

  onload() {
    console.clear();
    console.log("表格比较插件已加载");
    let blockId: string;
    window.addEventListener("mousedown", getBlockOnMousedown);
    function getBlockOnMousedown(event) {
      let x = event.clientX;
      let y = event.clientY;
      let element = document.elementFromPoint(x, y);
      if (!element) {
        return;
      }
      let dataNodeId: string | null;
      let parent = element.parentElement as HTMLElement;
      if (element.tagName == "BUTTON") {
        dataNodeId = element.getAttribute("data-node-id");
        if (dataNodeId) {
          blockId = dataNodeId;
          console.log(blockId);
          return;
        }
      }
      if (parent.tagName == "BUTTON") {
        dataNodeId = parent.getAttribute("data-node-id");
        if (dataNodeId) {
          blockId = dataNodeId;
          console.log(blockId);
          return;
        }
      }
    }
    
  }

  onunload() {
    console.log("plugin unload");
  }
}

//data-type,subtype=>nodeName
const dataType = {
  NodeHeading: {
    h1: "H1",
    h2: "H2",
    h3: "H3",
    h4: "H4",
    h5: "H5",
    h6: "H6",
  },
  NodeList: {
    u: "UL",
    o: "OL",
    t: "UL",
  },
  NodeListItem: "LI",
  NodeCodeBlock: "PRE",
  NodeMathBlock: "PRE",
  NodeParagraph: "P",
}; 